/*  KDevelop 4.3.1
 *  LUCKYNUM.cxx
 *
 * 	Author : Pallab
 * 	Created on: 10:36:06 PM - 2013:1:18
 * 	"I have not failed, I have just found 10000 ways that won't work."
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;


#define foR(i,frm,upto) for( int i=(frm),_i=(upto);(i) < (_i) ; ++i )
#define foD(i,frm,upto) for( int i=(frm),_i=(upto);(i) >= (_i) ; --i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait ( double seconds ) {
    double endtime = clock() + ( seconds * CLOCKS_PER_SEC );
    while ( clock() < endtime ) {
        ;
    }
}
template<class T>
    inline T fastIn() {
    register char c=0;
    register T a=0;
    bool neg=false;
    while ( c<33 ) c=getchar();
    while ( c>33 ) {
        if ( c=='-' ) {
            neg=true;
        } else {
            a= ( a*10 ) + ( c-'0' );
        }
        c=getchar();
    }
    return neg?-a:a;
}
int datasetCount;
int DIV;
inline void read() {
    DIV=fastIn<int>();
}
const int upto = 200;
inline void proc() {
    // total length,8count,6count;
    pair< int, pair<int,int> > bst;
    bool prothom=true;
    int modValue=0,mod1,mod2;
    for ( int eightCount=0; eightCount<=upto; ++eightCount ) {
        mod2=mod1=modValue;
        for ( int sixCount=0,baki=upto-eightCount; sixCount<=baki; ++sixCount ) {
            if ( eightCount||sixCount ) {
                if ( mod2==0 ) {
                    if ( prothom ) {
                        prothom=false;
                        bst = make_pair ( eightCount+sixCount, make_pair ( eightCount, sixCount ) );
                    } else {
                        bst = min ( bst, make_pair ( eightCount+sixCount, make_pair ( eightCount, sixCount ) ) );
                    }
                }
            }
            mod2= ( mod2*10+6 ) %DIV;
        }
        modValue= ( mod1*10+8 ) %DIV;
    }
    if ( prothom==true ) {
        puts ( "-1" );
    } else {
        foR ( i,0,bst.second.first ) putchar ( '8' );
        foR ( i,0,bst.second.second ) putchar ( '6' );
        puts ( "" );
    }
}
int main() {
    int kase = 1;
#if defined( xerxes_pc )
    freopen ( "in1", "r", stdin );
    kase = 1;
#endif
    kase=fastIn<int>();
    foR ( i,0,kase ) {
        read();
        proc();
    }

    return 0;
}

// kate: indent-mode cstyle; indent-width 4; replace-tabs on; 





